package com.suotuo.module.sys.controller;

import com.suotuo.common.util.Result;
import com.suotuo.module.sys.entity.Swiper;
import com.suotuo.module.sys.service.SwiperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author liulubingjava@163.com
 * @date 2019/1/22 14:04
 */
@RestController
@RequestMapping("swiper")
public class SwiperController {
    @Autowired
    private SwiperService swiperService;

    @RequestMapping("/list")
    public Result list(){
        return Result.success(swiperService.list());
    }
    @RequestMapping("/add")
    public Result add(@RequestBody Swiper swiper){
        swiperService.addSwiper(swiper);
        return Result.success("添加轮播图成功");
    }
    @RequestMapping("/updata")
    public Result updata(@RequestBody Swiper swiper,String swiperId){
        swiperService.update(swiper,swiperId);
        return Result.success("修改轮播图成功");
    }
    @RequestMapping("/delete/one")
    public Result deleteOne (@RequestParam String swiperId){
        swiperService.deleteOne(swiperId);
        return Result.success("删除单个轮播图成功");
    }
    @RequestMapping("/delete/more")
    public Result deleteMore(@RequestParam List<String> swiperIdList){
        for (String swiperId : swiperIdList){
            swiperService.deleteOne(swiperId);
        }
        return Result.success("删除多个轮播图成功");
    }
}
